package com.chen.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.admin.common.Result;
import com.chen.admin.entity.HotelRoom;
import com.chen.admin.service.HotelRoomService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:8080")
@RequestMapping("/hotelRoom")
public class HotelRoomController {


    @Autowired
    private HotelRoomService hotelRoomService;


    /**
     * 房间管理列表展示
     *
     * @param pageNumber
     * @param pageSize
     * @return
     */
//    @GetMapping("/hotelRoomGetPageList")
//    public Result<Page<HotelRoom>> hotelRoomGetPageList(@RequestParam(defaultValue = "1") Integer pageNumber,
//                                       @RequestParam(defaultValue = "10") Integer pageSize
//                                       ) {
//
//        Page<HotelRoom> hotelRoomPage = hotelRoomService.hotelRoomGetPageList(pageNumber, pageSize);
//        return Result.success(hotelRoomPage);
//
//
//    }
    @GetMapping("/hotelRoomGetPageList")
    public Result<PageInfo<HotelRoom>> hotelRoomGetPageList(@RequestParam(defaultValue = "1") Integer pageNumber,
                                                            @RequestParam(defaultValue = "10") Integer pageSize
    ) {

        PageHelper.startPage(pageNumber, pageSize);
        List<HotelRoom> hotelRoomList = hotelRoomService.hotelRoomGetPageList();

        return Result.success(new PageInfo<>(hotelRoomList));


    }

    /**
     * 新增房间
     */
    @PostMapping("/hotelRoomAdd")
    public Result<HotelRoom> hotelRoomAdd(@RequestBody HotelRoom hotelRoom) {
        Result result = hotelRoomService.hotelRoomAdd(hotelRoom);
        return result;
    }

    /**
     * 修改房间
     */

    @PutMapping("/updateHotelRoom")
    public Result updateHotelRoom(@RequestBody HotelRoom hotelRoom) {
        Result result = hotelRoomService.updateHotelRoom(hotelRoom);
        return result;
    }

    /**
     * 删除房间
     */
    @DeleteMapping("/deleteHotelRoom/{id}")
    public Result deleteHotelRoom(@PathVariable Integer id) {

        Result result = hotelRoomService.deleteHotelRoom(id);
        return result;

    }

    /**
     * 批量删除
     */

    @DeleteMapping("/deleteHotelRoomsByIds")
    public Result deleteHotelRoomsByIds(@RequestBody List<Integer> ids) {
        Result result = hotelRoomService.deleteHotelRoomsByIds(ids);
        return result;
    }

    /**
     * 根据房间名称查询
     */

    @GetMapping("/getHotelRoomByName")
    public Result<HotelRoom> getHotelRoomByName(@RequestParam("roomName") String roomName) {
        Result<HotelRoom> result = hotelRoomService.getHotelRoomByName(roomName);
        return result;
    }
}
